<?php 
	 class categoryControl extends Control{
	 	function index(){
	 		$db=M('category');
	 		$sql="select cid,cname,pid,concat(path,'_',cid)as p from com_category order by p";
			$category=$db->query($sql);
			foreach($category as $k=>$v){
				$count=count(explode("_",$v['p']))-2;
				$category[$k]['html']=str_repeat("-", $count*2);
			}
			$this->assign('category',$category);
	 		$this->display();
	 	}
	 	function addshow(){
	 		$cid=isset($_GET['cid'])?$_GET['cid']:false;
			$pid=0;
			$path=0;
			if($cid!==false){
				$db=M("category");
				$c=$db->find($cid);
				$pid=$cid;
				$path=$c['path'].'_'.$cid;
			}
			$this->assign('pid',$pid);
			$this->assign('path',$path);
	 		$this->display();
	 	}
	 	function add(){
	 		$db=M("category");
			$_POST['caddtime']=time();
			if($db->add()){
				$this->success("添加成功",'index');
			}else{
				$this->success("添加失败");
			}
	 	}
	 }
?>